//
//  CustomView.m
//  quickLook
//
//  Created by J on 15/9/6.
//  Copyright (c) 2015年 JZJ. All rights reserved.
//

#import "CustomView.h"

#import "Model.h"

#import "Header.h"

#import "ThirdNaviSearchController.h"

#import "FindViewController.h"
#import "IndividualViewController.h"

#import "IndividualVCHeaderEdit.h"

@interface CustomView ()<UIActionSheetDelegate>

@property (weak, nonatomic) IBOutlet UIView *orangeView;

@property (weak, nonatomic) IBOutlet UILabel *topic;
@property (weak, nonatomic) IBOutlet UIButton *seeMore;



@end
@implementation CustomView



- (void)awakeFromNib
{
    
    _orangeView.layer.cornerRadius=5;
    
    _orangeView.clipsToBounds=YES;
    
    
    //个人
    
    _individualIcon.layer.cornerRadius=35;

    _individualIcon.layer.masksToBounds=YES;
    
    
    //简介页icon
    _IntroAvatar_url.layer.cornerRadius=30;
    _IntroAvatar_url.layer.masksToBounds=YES;

}


//刷新介绍页headerView
- (void)refreshIntroduceVCWithModel:(Model*)model{

    [_IntroAvatar_url sd_setImageWithURL:[NSURL URLWithString:model.avatar_url] placeholderImage:[UIImage imageNamed:@"FIVEANGLE.png"]];
    
    _nickname.text=model.nickname;
    
    _intro.text=model.intro;

}







//刷新个人tableHeaderView


//individualIcon;
//individualNickName;

- (void)refreshIndividualTableHeaderViewWithDic:(NSDictionary*)dic
{
    _individualIcon.layer.borderWidth=1;
    _individualIcon.layer.borderColor=[[UIColor whiteColor]CGColor];
    
    
    [_individualIcon sd_setImageWithURL:dic[@"avatar_url"] forState:UIControlStateNormal] ;

    _individualNickName.text=dic[@"nickname"];
    
    _individualNickName.textColor=[UIColor whiteColor];
    
    if ([dic[@"nickname"] length]==0) {
//        JZJLog(@"xx");
        _individualNickName.text=@"登录";

    }
    
    
}






- (IBAction)seeMore:(UIButton*)sender {
    
    
    [self.findVCDelegate seeMoreWithModel:sender.tag];
    
    


}
- (void)refreshFindViewControllerTableHeaderView:(Model*)model
{
    static int i=0;
    i++;


    _topic.text=model.title;
    
    _seeMore.tag=i;

}

- (void)refreshHeaderLabelWithModel:(Model*)model
{


    _introduceLabel.text=model.Description;
    


}


- (void)refreshWithModel:(Model*)model
{


    
    
#pragma mark --背景图
    
    
    [_imageView sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url]];
    
    
    
#pragma mark --点赞数量
    _supportNumber.text=[NSString stringWithFormat:@"%d 万",[model.likes_count intValue]/10000];

    
#pragma mark --评论数量
    
    _commentNumber.text=[NSString stringWithFormat:@"%zd万",[model.comments_count integerValue]/10000];
    ;
    
    
    self.titleLabel.text=model.title;
    
    

    

}
//点击头像 如果不是登录状态  直接跳转登录页面
//IndividualViewControllerDelegate 登录跳转
- (IBAction)land:(id)sender {
    NSUserDefaults* userdefault=[NSUserDefaults standardUserDefaults];
    
    JZJLog(@"%d",[userdefault boolForKey:ISLAND]);
    
    
    if ([userdefault boolForKey:ISLAND]==NO) {
        
        
        
                LandController * vc=[[LandController alloc]init];
                
                
                [self.IndividualViewControllerDelegate.navigationController pushViewController:vc animated:YES];
                
                
    
        
        
        
    }else{
        
        
        if ([userdefault boolForKey:ISLAND]) {
            
            UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"退出登录",@"编辑资料", nil];
            actionSheet.tintColor=[UIColor orangeColor];
            
            actionSheet.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
            
            [actionSheet showInView:self];
            
        }

        
//    [self.IndividualViewControllerDelegate land];
        
    }
    
}





#pragma mark --UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    JZJLog(@"buttonIndex:%zd",buttonIndex);
    
    switch (buttonIndex) {
        case 0:
        {
            //退出登录
            
            NSUserDefaults* userdefault=[NSUserDefaults standardUserDefaults];
            
            
            NSDictionary* dic=[NSDictionary dictionary];
            [userdefault setObject:dic forKey:DATADIC];
            
            
            
            [userdefault setBool:NO forKey:ISLAND];
            
            //      BOOL island=  [userdefault boolForKey:ISLAND];
            [userdefault synchronize];
            
            
            
            //清空数据源 清除头像
            [self.IndividualViewControllerDelegate setValue:@[] forKey:@"TopicsArray"];//通过kvc 清空数组
            [self.IndividualViewControllerDelegate.tableView reloadData];
            
            
            [self.IndividualViewControllerDelegate refreshTableHeaderView];
            
            

        }
            break;
        case 1:
        {
            
            IndividualVCHeaderEdit* vc=[[IndividualVCHeaderEdit alloc]init];
            
            [self.IndividualViewControllerDelegate presentViewController:vc animated:YES completion:nil];

            
            
        }
            break;
    }
  
    
    




}





@end
